
package com.lucas.springboot_restful_api.vo;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;

public class PagingDozer<S, VO> extends Paging {

    @SuppressWarnings("unchecked")
    public PagingDozer(Page<S> pageS, Class<VO> classVO) {
        this.initPageParameters(pageS);

        List<S> sList = pageS.getContent();
        Mapper mapper = DozerBeanMapperBuilder.buildDefault();
        List<VO> voList = new ArrayList<>();

        sList.forEach(s -> {
            VO vo = mapper.map(s, classVO);
            voList.add(vo);
        });
        this.setItems(voList);
    }

}
